package org.apache.streampark.console.core.controller;

import io.swagger.v3.oas.annotations.Operation;
import org.apache.streampark.console.base.domain.RestResponse;
import org.apache.streampark.console.core.annotation.ApiAccess;
import org.apache.streampark.console.core.entity.Application;
import org.apache.streampark.console.core.service.StatisticsService;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.annotation.Resource;
import java.util.List;
import java.util.Map;

/*
    首页
*/
@RequestMapping("index/statistics")
@Controller
public class StatisticsController {
    @Resource
    private StatisticsService statisticsService;

    @Operation(summary = "任务统计")
    @GetMapping("taskstatistics")
    @ResponseBody
    public RestResponse statisticsTask(Long teamId) {
        Map<String,Integer> map = statisticsService.getTaskStatistics((teamId));
        return RestResponse.success(map);
    }

    @Operation(summary = "运行中作业TOP5")
    @GetMapping("runningTask")
    @ResponseBody
    public RestResponse runningTask(Long teamId) {
        List<Application> list = statisticsService.queryRunningTask(teamId);
        return RestResponse.success(list);
    }

    @Operation(summary = "已完成作业TOP5")
    @GetMapping("completedTask")
    @ResponseBody
    public RestResponse completedTask(Long teamId) {
        List<Application> list = statisticsService.queryCompletedTask(teamId);
        return RestResponse.success(list);
    }

}
